package com.rigsofrods.truckeditor.rig.parser;


import java.text.ParseException;
import java.util.InputMismatchException;
import java.util.Locale;
import java.util.Scanner;

import com.rigsofrods.truckeditor.rig.TruckModel;
import com.rigsofrods.truckeditor.rig.TruckTreeNode;


public class CamerasParser implements IRigParser {

	@Override
	public boolean parseLine(String line, TruckModel truck) throws ParseException {
		String center, back, left;

		Scanner scanner = new Scanner(line);
		scanner.useLocale(Locale.US);
		scanner.useDelimiter("(\\s+|,\\s*)");
		try{
			center = scanner.next();
			back = scanner.next();
			left = scanner.next();
		}catch (InputMismatchException e) {
			return false;
		}finally{
			scanner.close();
		}
		if(truck.getNode(center) == null)
			throw new ParseException("Camera node Center: " + center + " has not been defined in truck file!", 0);
		if(truck.getNode(back) == null)
			throw new ParseException("Camera node Back: " + back + " has not been defined in truck file!", 0);
		if(truck.getNode(left) == null)
			throw new ParseException("Camera node Left: " + left + " has not been defined in truck file!", 0);
		//TODO: Process camera nodes!
		return true;
	}

	@Override
	public String getErrorMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean requestComments() {
		// TODO Auto-generated method stub
		return false;
	}

}
